package com.adlx.dingdong.mall.dto;

import com.alibaba.fastjson.JSON;

public class Result<T> {

    private boolean success;
    private String msg;
    private Integer code;
    private T data;

    public static <T> Result<T> success(T result) {
        return new Result<T>(true, 200, "", result);
    }

    public static <T> Result<T> success(T result, String msg) {
        return new Result<T>(true, 200, msg, result);
    }

    public static Result<String> error(String message) {
        return new Result<String>(false, 404, message);
    }

    public static Result<String> error(String message, Integer code) {
        return new Result<String>(false, code, message);
    }

    public Result() {
        super();
        this.success = true;
        this.code = 200;
    }

    public Result(boolean success) {
        super();
        this.success = success;
    }

    public Result(boolean success, int code, String msg) {
        super();
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public Result(boolean success, T data) {
        super();
        this.success = success;
        this.data = data;
    }

    public Result(boolean success, Integer code, String msg, T data) {
        super();
        this.success = success;
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }


}
